#include <stdlib.h>
#include <stdio.h>
#include <nds.h>

// common headers
#include "common.h"

// local headers
#if defined(Library)    // for std
#    include "library.h"
#elif defined(Plugin)
#    include "plugin.h"
#endif

#include "binary.h"

sStd *std;  // standard functions
sNds *nds;  // libnds functions
sX *x;      // xlibrary functions
sF *f;      // file functions
sFL *fl;    // filelist functions
sLL *ll;    // linked list functions
sLF *lf;    // lifo functions
sAPI *api;  // SunOS API functions
sMM *mm;    // maxmod functions

// some gcc functions
void __aeabi_idiv() {
    std->__aeabi_idiv();
}
void __aeabi_idivmod() {
    std->__aeabi_idivmod();
}
void __aeabi_uidiv() {
    std->__aeabi_uidiv();
}
void __aeabi_ldivmod() {
    std->__aeabi_ldivmod();
}

inline int binaryInit(sLibs *libs) {
    if(!libs || !VERSION_IS_COMPATIBLE(libs->version, LIBS_VERSION)) return 1;

    // setup function pointers
    std=libs->std;  if(!std || !VERSION_IS_COMPATIBLE(std->version, STD_VERSION)) return 1;
    nds=libs->nds;  if(!nds || !VERSION_IS_COMPATIBLE(nds->version, NDS_VERSION)) return 1;
    x=libs->x;      if(!x   || !VERSION_IS_COMPATIBLE(x->version,   X_VERSION)  ) return 1;
    f=libs->f;      if(!f   || !VERSION_IS_COMPATIBLE(f->version,   F_VERSION)  ) return 1;
    fl=libs->fl;    if(!fl  || !VERSION_IS_COMPATIBLE(fl->version,  FL_VERSION) ) return 1;
    ll=libs->ll;    if(!ll  || !VERSION_IS_COMPATIBLE(ll->version,  LL_VERSION) ) return 1;
    lf=libs->lf;    if(!lf  || !VERSION_IS_COMPATIBLE(lf->version,  LF_VERSION) ) return 1;
    api=libs->api;  if(!api || !VERSION_IS_COMPATIBLE(api->version, API_VERSION)) return 1;
    mm=libs->mm;    if(!mm  || !VERSION_IS_COMPATIBLE(mm->version,  MM_VERSION) ) return 1;

    return 0;
}

